package com.jhws.sys.cms.service;

import com.jhws.core.db.BaseDao;
import com.jhws.sys.cms.bo.ImagesOss;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ImagesOssService {

    @Resource
    private BaseDao BaseDao;

    /**
     * 保存oss图片信息
     *
     * @param imagesOss 图片信息
     */
    public void saveImagesOssInfo(ImagesOss imagesOss) {
        if (imagesOss.getId() == 0) {
            BaseDao.h().save(imagesOss);
        } else {
            BaseDao.h().update(imagesOss);
        }
    }


    /**
     * 修改受控状态
     *
     * @param resourceUId  //资源id
     * @param isControlled //受控状态
     */
    public void updateControlled(String resourceUId, int isControlled) {
        BaseDao.j().execute("UPDATE cms_images_oss SET is_controlled = '" + isControlled + "' WHERE resource_uid = '" + resourceUId + "' ");
    }

    /**
     * 条件删除
     *
     * @param where 条件
     */
    public void deleteImagesOss(String where) {
        String sql = "delete from cms_images_oss " + where;
        BaseDao.j().execute(sql);
    }

    public List<ImagesOss> findImagesOssByWhere(String where) {
        return BaseDao.findList("from ImagesOss " + where);
    }
}
